﻿function detail_warn(modelId, warnId) {
    top.learun.layerForm({
        id: 'preview_result' + modelId,
        title: '查看告警',
        url: config.webportal_server + 'pages/finance/audit_rule/preview_result/result' + modelId + '.html?modelId=' + modelId + '&warnId=' + warnId + '&access_token=' + config.getToken().access_token,
        width: 1000,
        height: 800,
        maxmin: true,
        btn: null
    });
    // top.learun.frameTab.open({
    //     id: 'preview_result' + modelId + "_" + warnId,
    //     css: 'fa magic',
    //     name: '查看告警',
    //     path: config.webportal_server + 'pages/finance/audit_rule/preview_result/result' + modelId + '.html?modelId=' + modelId + '&warnId=' + warnId + '&access_token=' + config.getToken().access_token,
    // });

}

function detail_task(processId, taskId, processName) {
    if (top.learun.checkrow(processId)) {
        top.learun.frameTab.open({
            id: processId + taskId,
            css: 'fa magic',
            name: '查看流程进度【' + processName + '】',
            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?tabIframeId=' + processId + taskId + '&type=100' + "&processId=" + processId + "&taskId=" + taskId + '&access_token=' + config.getToken().access_token
        });
    }
}


function loadData1() {
    //代办
    $.ajax({
        url: config.base_server() + 'wftasks?access_token=' + config.getToken().access_token,
        data: {
            page: 1,
            limit: 8,
            categoryId: 2
        },
        type: 'GET',
        //  dataType: "json",
        success: function (res) {
            $("#need_count").html(res.count);
            if (!!res.data) {
                var $html = "";
                for (var i = 0; i < res.data.length; i++) {
                    $html += ' <div class="lr-msg-line">';
                    $html += '    <a onclick="detail_task(\'' + res.data[i].id + '\',\'' + res.data[i].taskId + '\',\'' + res.data[i].processName + '\')" style="text-decoration: none;">['+ res.data[i].companyName +']&nbsp;&nbsp;&nbsp;' + res.data[i].processName + '[' + res.data[i].code + ']</a>';
                    $html += '    <label>' + res.data[i].createTime + '</label>';
                    $html += '</div>';
                }
                $("#div_task1").append($html);
            }
        }
    });
};

function loadData2() {
    //已办
    $.ajax({
        url: config.base_server() + 'wftasks?access_token=' + config.getToken().access_token,
        data: {
            page: 1,
            limit: 8,
            categoryId: 3
        },
        type: 'GET',
        //  dataType: "json",
        success: function (res) {
            $("#already_count").html(res.count);
            if (!!res.data) {
                var $html = "";
                for (var i = 0; i < res.data.length; i++) {
                    $html += ' <div class="lr-msg-line">';
                    $html += '    <a onclick="detail_task(\'' + res.data[i].id + '\',\'' + res.data[i].taskId + '\',\'' + res.data[i].processName + '\')" style="text-decoration: none;">['+ res.data[i].companyName +']&nbsp;&nbsp;&nbsp;' + res.data[i].processName + '[' + res.data[i].code + ']</a>';
                    $html += '    <label>' + res.data[i].createTime + '</label>';
                    $html += '</div>';
                }
                $("#div_task2").append($html);
            }
        }
    });
};

function loadData3() {
    //告警-代办
    $.ajax({
        url: config.base_server() + 'auditmodelwarns/list?access_token=' + config.getToken().access_token,
        data: {
            page: 1,
            limit: 8,
            readFlag: 0
        },
        type: 'GET',
        //  dataType: "json",
        success: function (res) {
            $("#need_count").html(res.count);
            if (!!res.data) {
                var $html = "";
                for (let i = 0; i < res.data.length; i++) {
                    $html += ' <div class="lr-msg-line">';
                    $html += '    <a onclick="detail_warn(\'' + res.data[i].modelId + '\',\'' + res.data[i].id + '\')" style="text-decoration: none;"><i class="fa fa-envelope" style="color:goldenrod;font-size: 15px;"></i>&nbsp;&nbsp;&nbsp;' + res.data[i].modelName + '</a>';
                    $html += '    <label>' + res.data[i].createTime + '</label>';
                    $html += '</div>';
                }
                $("#div_warn1").append($html);
            }
        }
    });
};

function loadData4() {
    //告警-已办
    $.ajax({
        url: config.base_server() + 'auditmodelwarns/list?access_token=' + config.getToken().access_token,
        data: {
            page: 1,
            limit: 8,
            readFlag: 1
        },
        type: 'GET',
        //  dataType: "json",
        success: function (res) {
            $("#already_count").html(res.count);
            if (!!res.data) {
                var $html = "";
                for (let i = 0; i < res.data.length; i++) {
                    $html += ' <div class="lr-msg-line">';
                    $html += '    <a onclick="detail_warn(\'' + res.data[i].modelId + '\',\'' + res.data[i].id + '\')" style="text-decoration: none;"><i class="fa fa-envelope-open" style="color:goldenrod;font-size: 15px;"></i>&nbsp;&nbsp;&nbsp;' + res.data[i].modelName + '</a>';
                    $html += '    <label>' + res.data[i].createTime + '</label>';
                    $html += '</div>';
                }
                $("#div_warn2").append($html);
            }
        }
    });
};

function loadData5() {
    //统计指标
    $.ajax({
        url: config.base_server() + 'auditmodelwarns/count?access_token=' + config.getToken().access_token,
        data: {},
        type: 'GET',
        success: function (res) {
            if (!!res.data) {
                $("#warn_totalCount").html(res.data.totalCount);
                $("#warn_nomalCount").html(res.data.nomalCount);
                $("#warn_errorCount").html(res.data.errorCount);
                $("#warn_dealCompleteCount").html(res.data.dealCompleteCount);
                $("#warn_dealDoingCount").html(res.data.dealDoingCount);

                renderEChart1(res.data);
                renderEChart2(res.data);

                renderCompanyWarnTable("companywarn_tbody1", res.data.companywarnDetail1);
                renderCompanyWarnTable("companywarn_tbody2", res.data.companywarnDetail2);
                renderCompanyWarnTable("companywarn_tbody3", res.data.companywarnDetail3);
            }
        }
    });
};


function renderEChart1(res) {
   var chartDom = document.getElementById('chart1');
   var myChart = echarts.init(chartDom);
   var option = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '90%',
        left: 'center'
      },
      color: ['#FFA813', '#137DFF', '#93BEFF', '#F07A67', '#f9c956', '#75bedc'],
      series: [
        {
          name: '分类统计',
          type: 'pie',
          radius: ['36%', '52%'],
          data: res.echartCategories,
          label: {
            show: true,
            formatter(param) {
              // correct the percentage
              return param.name + ' (' + param.value  + ')';
            }
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    option && myChart.setOption(option);
}

function renderEChart2(res) {
    var html = "";

    for(var i=0;i<res.echartCompanys.length;i++) {
        if(res.echartCompanys[i].name.substring(0,2)=="00") {
           html+= '<div style="height:31px;line-height:31px;"><span>00 市院&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(179deg, #2DC9EB 0%, #14D2B8 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="01 天河") {
           html+= ' <div style="height:31px;line-height:31px;"><span>01 天河&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(180deg, #F15887 -22%, #FE9B86 133%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="02 海珠") {
          html+= '  <div style="height:31px;line-height:31px;"><span>02 海珠&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(0deg, #199FFF 0%, #254BFF 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="03 越秀") {
           html+= ' <div style="height:31px;line-height:31px;"><span>03 越秀&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(179deg, #2DC9EB 0%, #14D2B8 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="04 荔湾") {
           html+= ' <div style="height:31px;line-height:31px;"><span>04 荔湾&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: #FFAA40;"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="05 白云") {
           html+= '  <div style="height:31px;line-height:31px;"><span>05 白云&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(179deg, #F15887 -22%, #FE9B86 132%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="06 番禺") {
           html+= ' <div style="height:31px;line-height:31px;"><span>06 番禺&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: #FFAA40;"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="07 黄埔") {
           html+= ' <div style="height:31px;line-height:31px;"><span>07 黄埔&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(0deg, #199FFF 0%, #254BFF 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="08 南沙") {
           html+= ' <div style="height:31px;line-height:31px;"><span>08 南沙&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(180deg, #F15887 -22%, #FE9B86 133%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="09 花都") {
           html+= '  <div style="height:31px;line-height:31px;"><span>09 花都&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(0deg, #199FFF 0%, #254BFF 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="10 增城") {
           html+= '  <div style="height:31px;line-height:31px;"><span>10 增城&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: linear-gradient(179deg, #2DC9EB 0%, #14D2B8 99%);"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
        else if(res.echartCompanys[i].name=="11 从化") {
           html+= '  <div style="height:31px;line-height:31px;"><span>11 从化&nbsp;&nbsp;</span><span style="display: inline-block;width: '+res.echartCompanys[i].value*10+'px;height: 12px;border-radius: 4px;background: #FFAA40;"></span><span>&nbsp;&nbsp;'+res.echartCompanys[i].value+'个</span></div>';
        }
    }
    $("#chart2").append(html);
}

function renderCompanyWarnTable(dom, data) {
    var html = "";
    for(var i=0;i<data.length;i++) {
        html += ' <tr>';
        html += '<td>'+ data[i].companyName +'</td>';
        html += '<td style="text-align:center;">'+ data[i].finance +'</td>';
        html += '<td style="text-align:center;">'+ data[i].pay +'</td>';
        html += '<td style="text-align:center;">'+ data[i].reimburse +'</td>';
        html += '<td style="text-align:center;">'+ data[i].asset +'</td>';
        html += '<td style="text-align:center;">'+ data[i].purchase +'</td>';
        html += '<td style="text-align:center;">'+ data[i].car +'</td>';
        html += '<td style="text-align:center;">'+ data[i].other +'</td>';
        html += ' </tr>';
    }
    $("#"+dom).append(html);
}

function moreRedirect() {
    $("#more_task").click(function () {
        top.learun.frameTab.open({
            id: top.learun.newGuid(),
            css: 'fa task1',
            name: '我的代办',
            path: config.webportal_server + 'pages/workflow/wfmyTask/index.html?categoryId=2&access_token=' + config.getToken().access_token
        });
    })
    $("#more_warn").click(function () {
        top.learun.frameTab.open({
            id: top.learun.newGuid(),
            css: 'fa warn1',
            name: '我的告警',
            path: config.webportal_server + 'pages/finance/audit_warn/index.html?ingoreFlag=0&access_token=' + config.getToken().access_token
        });
    })
    $("#warn1_click").click(function () {
        top.learun.frameTab.open({
            id: top.learun.newGuid(),
            css: 'fa warn1',
            name: '告警列表',
            path: config.webportal_server + 'pages/finance/audit_warn/index_all.html?access_token=' + config.getToken().access_token
        });
    })
    $("#warn1_click").mouseover(function() {
         $("#toggle_warn_table1").show();
    });
    $("#warn1_click").mouseout(function() {
         $("#toggle_warn_table1").hide();
    });

    $("#warn2_click").mouseover(function() {
         $("#toggle_warn_table2").show();
    });
    $("#warn2_click").mouseout(function() {
         $("#toggle_warn_table2").hide();
    });

    $("#warn3_click").mouseover(function() {
         $("#toggle_warn_table3").show();
    });
    $("#warn3_click").mouseout(function() {
         $("#toggle_warn_table3").hide();
    });
}


$(document).ready(function () {
    loadData1();
    loadData2();
    loadData3();
    loadData4();
    loadData5();

    toggleClick();
    moreRedirect();
    // resize();

    // $('.lr-desktop-panel').css("height",$(window).height() - 300+"px;overflow-y:auto;");
});

function toggleClick() {
    $("#span_task1").click(function () {
        $("#span_task1").addClass("active").removeClass("notactive");
        $("#span_task2").addClass("notactive").removeClass("active");
        $("#div_task1").show();
        $("#div_task2").hide();

        $("#more_task").click(function () {
            top.learun.frameTab.open({
                id: top.learun.newGuid(),
                css: 'fa task1',
                name: '我的任务',
                path: config.webportal_server + 'pages/workflow/wfmyTask/index.html?categoryId=2&access_token=' + config.getToken().access_token
            });
        })
    });
    $("#span_task2").click(function () {
        $("#span_task2").addClass("active").removeClass("notactive");
        $("#span_task1").addClass("notactive").removeClass("active");
        $("#div_task2").show();
        $("#div_task1").hide();

        $("#more_task").click(function () {
            top.learun.frameTab.open({
                id: top.learun.newGuid(),
                css: 'fa task2',
                name: '我的任务',
                path: config.webportal_server + 'pages/workflow/wfmyTask/index.html?categoryId=3&access_token=' + config.getToken().access_token
            });
        })
    });
    $("#span_warn1").click(function () {
        $("#span_warn1").addClass("active").removeClass("notactive");
        $("#span_warn2").addClass("notactive").removeClass("active");
        $("#div_warn1").show();
        $("#div_warn2").hide();

        $("#more_warn").click(function () {
            top.learun.frameTab.open({
                id: top.learun.newGuid(),
                css: 'fa warn1',
                name: '我的告警',
                path: config.webportal_server + 'pages/finance/audit_warn/index.html?ingoreFlag=0&access_token=' + config.getToken().access_token
            });
        })
    });
    $("#span_warn2").click(function () {
        $("#span_warn2").addClass("active").removeClass("notactive");
        $("#span_warn1").addClass("notactive").removeClass("active");
        $("#div_warn2").show();
        $("#div_warn1").hide();

        $("#more_warn").click(function () {
            top.learun.frameTab.open({
                id: top.learun.newGuid(),
                css: 'fa warn2',
                name: '我的告警',
                path: config.webportal_server + 'pages/finance/audit_warn/index.html?ingoreFlag=1&access_token=' + config.getToken().access_token
            });
        })
    });
}

function quickMenu(url,name) {
    var uuid = Math.uuid();
    top.learun.frameTab.open({
        id: uuid,
        css: 'fa magic',
        name: name,
        path: config.webportal_server + url + '?access_token=' + config.getToken().access_token
    });
}


